/*
 * QE3e Qt Quick 3D Engine.
 * Copyright (C) 2010 Joris Vaillant and Mathieu Pujol 
 * <joris.vaillant@gmail.com>  <mathieu.pujol87@gmail.com>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */


#ifndef QE3E_TEXTURE_H
#define QE3E_TEXTURE_H

// QE3E
#include <qe3e_global.h>

// OpenGL
#include <qe3e_opengl.h>

// Qt4
#include <QString>
#include <QSharedDataPointer>
#include <QColor>


/** @todo gestion des matrices pour les shadowmap
  *       tester la classe
  */
namespace qe3e
{
  // forward declaration
  class TexturePrivate;

  class QE3E_EXPORT Texture
  {
  public:
    void unbindTexture(int unitIndex);

    enum TextureType {diffuse = 0, specular, ambient, normalMap, heightMap, other};

    //Texture(const QString& fileName, Texture::TextureType type = diffuse);
    Texture(GLuint texId, Texture::TextureType type = diffuse);
    Texture(const Texture & cpy);
    virtual ~Texture();

    TextureType getType() const;

    void bindTexture(int texUnit);

    void setFilteringMode(GLint min, GLint mag);
    void setWrapMode(GLint s, GLint t);
    void setClampColor(const QColor& color);
    void setBlendingMode(GLint);

    void setTexId(GLuint texId);
    const GLuint & getTexId() const;

    bool isValid() const;
  private:
   // void loadTexture(const QString fileName = "");

    QSharedDataPointer<TexturePrivate> m_data;
    GLuint mTexId;
  };

  class TexturePrivate : public QSharedData
    {
    public:
      TexturePrivate();
    //  TexturePrivate(const TexturePrivate & cpy);
     // ~TexturePrivate();

     // void setTexId(GLuint texId);
     // const GLuint & getTexId() const;
     /* TexturePrivate(const TexturePrivate & texP);
      TexturePrivate & operator=(const TexturePrivate & texP);
*/

      GLint wrapMode[2];
      GLint filteringMode[2];
      GLint blendingMode;
      QColor clampColor;
      Texture::TextureType type;

   // private:
      // GLuint mTexId;
    };
}
#endif // QE3E_TEXTURE_H
